package cn.itsource.system.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.itsource.system.domain.Permission;
import cn.itsource.system.mapper.PermissionMapper;
import cn.itsource.system.query.PermissionQuery;
import cn.itsource.system.service.IPermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * 业务实现类：权限Permission
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public List<Permission> findAll() {
        return permissionMapper.findAll();
    }

    @Override
    public Permission findOne(Long id) {
        return permissionMapper.findOne(id);
    }

    @Transactional
    @Override
    public void add(Permission permission) {
        permissionMapper.add(permission);
    }

    @Transactional
    @Override
    public void update(Permission permission) {
        permissionMapper.update(permission);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        permissionMapper.delete(id);
    }

    @Transactional
    @Override
    public void patchDel(Long[] ids) {
        permissionMapper.patchDel(ids);
    }

    @Override
    public PageInfo<Permission> queryPage(PermissionQuery permissionQuery) {
        //开启分页
        PageHelper.startPage(permissionQuery.getCurrentPage(),permissionQuery.getPageSize());
        //1.首先会查询总条数
        //2.会根据方言或驱动名进行分页查询数据 - mysql - limit
        //3.会自动计算limit的第一个参数

        List<Permission> list = permissionMapper.queryPage(permissionQuery);
        //调用PageInfo的有参会计算其他参数
        PageInfo<Permission> pageInfo = new PageInfo<Permission>(list);
        return pageInfo;
    }
}
